/*     */ package com.umeng.common.net;
/*     */ 
/*     */ import com.umeng.common.Log;
/*     */ import com.umeng.common.util.f;
/*     */ import com.umeng.common.util.h;
/*     */ import java.io.BufferedReader;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.InputStreamReader;
/*     */ import java.lang.reflect.Constructor;
/*     */ import java.lang.reflect.InvocationTargetException;
/*     */ import java.nio.charset.Charset;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Random;
/*     */ import java.util.Set;
/*     */ import java.util.zip.GZIPInputStream;
/*     */ import java.util.zip.InflaterInputStream;
/*     */ import org.apache.http.Header;
/*     */ import org.apache.http.HttpEntity;
/*     */ import org.apache.http.HttpResponse;
/*     */ import org.apache.http.StatusLine;
/*     */ import org.apache.http.client.ClientProtocolException;
/*     */ import org.apache.http.client.HttpClient;
/*     */ import org.apache.http.client.entity.UrlEncodedFormEntity;
/*     */ import org.apache.http.client.methods.HttpGet;
/*     */ import org.apache.http.client.methods.HttpPost;
/*     */ import org.apache.http.entity.InputStreamEntity;
/*     */ import org.apache.http.impl.client.DefaultHttpClient;
/*     */ import org.apache.http.message.BasicNameValuePair;
/*     */ import org.apache.http.params.BasicHttpParams;
/*     */ import org.apache.http.params.HttpConnectionParams;
/*     */ import org.apache.http.params.HttpParams;
/*     */ import org.apache.http.params.HttpProtocolParams;
/*     */ import org.json.JSONException;
/*     */ import org.json.JSONObject;
/*     */ 
/*     */ public class s
/*     */ {
/*  54 */   private static final String a = s.class.getName();
/*     */   private Map<String, String> b;
/*     */ 
/*     */   public <T extends u> T execute(t paramt, Class<T> paramClass)
/*     */   {
/*  72 */     String str = paramt.c().trim();
/*  73 */     b(str);
/*     */ 
/*  75 */     JSONObject localJSONObject = null;
/*  76 */     if (t.c.equals(str))
/*  77 */       localJSONObject = a(paramt.b());
/*  78 */     else if (t.b.equals(str)) {
/*  79 */       localJSONObject = a(paramt.d, paramt.a());
/*     */     }
/*     */ 
/*  82 */     if (localJSONObject == null) {
/*  83 */       return null;
/*     */     }
/*     */ 
/*     */     try
/*     */     {
/*  88 */       Constructor localConstructor = paramClass.getConstructor(new Class[] { JSONObject.class });
/*  89 */       return (u)localConstructor.newInstance(new Object[] { localJSONObject });
/*     */     } catch (SecurityException localSecurityException) {
/*  91 */       Log.b(a, "SecurityException", localSecurityException);
/*     */     } catch (NoSuchMethodException localNoSuchMethodException) {
/*  93 */       Log.b(a, "NoSuchMethodException", localNoSuchMethodException);
/*     */     } catch (IllegalArgumentException localIllegalArgumentException) {
/*  95 */       Log.b(a, "IllegalArgumentException", localIllegalArgumentException);
/*     */     } catch (InstantiationException localInstantiationException) {
/*  97 */       Log.b(a, "InstantiationException", localInstantiationException);
/*     */     } catch (IllegalAccessException localIllegalAccessException) {
/*  99 */       Log.b(a, "IllegalAccessException", localIllegalAccessException);
/*     */     } catch (InvocationTargetException localInvocationTargetException) {
/* 101 */       Log.b(a, "InvocationTargetException", localInvocationTargetException);
/*     */     }
/* 103 */     return null;
/*     */   }
/*     */ 
/*     */   private JSONObject a(String paramString, JSONObject paramJSONObject) {
/* 107 */     String str1 = paramJSONObject.toString();
/* 108 */     int i = new Random().nextInt(1000);
/* 109 */     Log.c(a, i + ":\trequest: " + paramString + h.a + str1);
/*     */ 
/* 112 */     HttpPost localHttpPost = new HttpPost(paramString);
/*     */ 
/* 114 */     HttpParams localHttpParams = a();
/* 115 */     DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(localHttpParams);
/*     */     try
/*     */     {
/* 121 */       String str2 = str1;
/*     */       Object localObject2;
/* 122 */       if (shouldCompressData()) {
/* 123 */         str2 = "content=" + str2;
/* 124 */         localObject1 = f.a(str2, 
/* 125 */           Charset.defaultCharset().toString());
/* 126 */         localHttpPost.addHeader("Content-Encoding", "deflate");
/* 127 */         localObject2 = new InputStreamEntity(
/* 128 */           new ByteArrayInputStream((byte[])localObject1), localObject1.length);
/* 129 */         localHttpPost.setEntity((HttpEntity)localObject2);
/*     */       } else {
/* 131 */         localObject1 = new ArrayList(
/* 132 */           1);
/* 133 */         ((List)localObject1).add(new BasicNameValuePair("content", str2));
/* 134 */         localHttpPost.setEntity(new UrlEncodedFormEntity((List)localObject1, 
/* 135 */           "UTF-8"));
/*     */       }
/*     */ 
/* 138 */       Object localObject1 = localDefaultHttpClient.execute(localHttpPost);
/* 139 */       if (((HttpResponse)localObject1).getStatusLine().getStatusCode() == 200)
/*     */       {
/* 141 */         localObject2 = ((HttpResponse)localObject1).getEntity();
/*     */ 
/* 143 */         if (localObject2 != null) {
/* 144 */           Object localObject3 = ((HttpEntity)localObject2).getContent();
/* 145 */           Header localHeader = ((HttpResponse)localObject1).getFirstHeader("Content-Encoding");
/*     */ 
/* 147 */           if ((localHeader != null) && 
/* 148 */             (localHeader.getValue().equalsIgnoreCase("deflate"))) {
/* 149 */             localObject3 = new InflaterInputStream((InputStream)localObject3);
/*     */           }
/*     */ 
/* 152 */           String str3 = a((InputStream)localObject3);
/* 153 */           Log.a(a, i + ":\tresponse: " + h.a + 
/* 154 */             str3);
/*     */ 
/* 156 */           if (str3 == null) {
/* 157 */             return null;
/*     */           }
/* 159 */           return new JSONObject(str3);
/*     */         }
/* 161 */         return null;
/*     */       }
/* 163 */       Log.c(a, i + ":\tFailed to send message. StatusCode = " + 
/* 164 */         ((HttpResponse)localObject1).getStatusLine().getStatusCode() + 
/* 165 */         h.a + paramString);
/* 166 */       return null;
/*     */     }
/*     */     catch (ClientProtocolException localClientProtocolException) {
/* 169 */       Log.c(a, 
/* 170 */         i + 
/* 171 */         ":\tClientProtocolException,Failed to send message." + 
/* 172 */         paramString, localClientProtocolException);
/* 173 */       return null;
/*     */     } catch (IOException localIOException) {
/* 175 */       Log.c(a, i + ":\tIOException,Failed to send message." + paramString, 
/* 176 */         localIOException);
/* 177 */       return null;
/*     */     } catch (JSONException localJSONException) {
/* 179 */       Log.c(a, i + ":\tIOException,Failed to send message." + paramString, 
/* 180 */         localJSONException);
/* 181 */     }return null;
/*     */   }
/*     */ 
/*     */   public boolean shouldCompressData()
/*     */   {
/* 186 */     return false;
/*     */   }
/*     */ 
/*     */   private static String a(InputStream paramInputStream) {
/* 190 */     BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(paramInputStream), 
/* 191 */       8192);
/* 192 */     StringBuilder localStringBuilder = new StringBuilder();
/*     */ 
/* 194 */     Object localObject1 = null;
/*     */     try {
/* 196 */       while ((localObject1 = localBufferedReader.readLine()) != null)
/* 197 */         localStringBuilder.append(localObject1 + "\n");
/*     */     }
/*     */     catch (IOException localIOException1) {
/* 200 */       Log.b(a, "Caught IOException in convertStreamToString()", localIOException1);
/* 201 */       return null;
/*     */     } finally {
/*     */       try {
/* 204 */         paramInputStream.close();
/*     */       } catch (IOException localIOException3) {
/* 206 */         Log.b(a, "Caught IOException in convertStreamToString()", localIOException3);
/* 207 */         return null;
/*     */       }
/*     */     }
/* 210 */     return localStringBuilder.toString();
/*     */   }
/*     */ 
/*     */   private JSONObject a(String paramString) {
/* 214 */     int i = new Random().nextInt(1000);
/*     */     try {
/* 216 */       String str1 = System.getProperty("line.separator");
/* 217 */       if (paramString.length() <= 1) {
/* 218 */         Log.b(a, i + ":\tInvalid baseUrl.");
/* 219 */         return null;
/*     */       }
/*     */ 
/* 222 */       Log.a(a, i + ":\tget: " + paramString);
/* 223 */       HttpGet localHttpGet = new HttpGet(paramString);
/*     */ 
/* 225 */       if ((this.b != null) && (this.b.size() > 0)) {
/* 226 */         localObject1 = this.b.keySet();
/* 227 */         for (localObject3 = ((Set)localObject1).iterator(); ((Iterator)localObject3).hasNext(); ) { localObject2 = (String)((Iterator)localObject3).next();
/* 228 */           localHttpGet.addHeader((String)localObject2, (String)this.b.get(localObject2));
/*     */         }
/*     */       }
/* 231 */       Object localObject1 = a();
/*     */ 
/* 233 */       Object localObject2 = new DefaultHttpClient((HttpParams)localObject1);
/* 234 */       Object localObject3 = ((HttpClient)localObject2).execute(localHttpGet);
/*     */ 
/* 236 */       if (((HttpResponse)localObject3).getStatusLine().getStatusCode() == 200)
/*     */       {
/* 238 */         HttpEntity localHttpEntity = ((HttpResponse)localObject3).getEntity();
/*     */ 
/* 240 */         if (localHttpEntity != null) {
/* 241 */           Object localObject4 = localHttpEntity.getContent();
/* 242 */           Header localHeader = ((HttpResponse)localObject3).getFirstHeader("Content-Encoding");
/*     */ 
/* 244 */           if ((localHeader != null) && 
/* 245 */             (localHeader.getValue().equalsIgnoreCase("gzip"))) {
/* 246 */             Log.a(a, i + 
/* 247 */               "  Use GZIPInputStream get data....");
/* 248 */             localObject4 = new GZIPInputStream((InputStream)localObject4);
/* 249 */           } else if ((localHeader != null) && 
/* 250 */             (localHeader.getValue().equalsIgnoreCase("deflate"))) {
/* 251 */             Log.a(a, i + 
/* 252 */               "  Use InflaterInputStream get data....");
/* 253 */             localObject4 = new InflaterInputStream((InputStream)localObject4);
/*     */           }
/*     */ 
/* 256 */           String str2 = a((InputStream)localObject4);
/* 257 */           Log.a(a, i + ":\tresponse: " + str1 + 
/* 258 */             str2);
/*     */ 
/* 260 */           if (str2 == null) {
/* 261 */             return null;
/*     */           }
/* 263 */           return new JSONObject(str2);
/*     */         }
/*     */       } else {
/* 266 */         Log.c(a, i + ":\tFailed to send message. StatusCode = " + 
/* 267 */           ((HttpResponse)localObject3).getStatusLine().getStatusCode() + 
/* 268 */           h.a + paramString);
/*     */       }
/* 270 */       return null;
/*     */     } catch (ClientProtocolException localClientProtocolException) {
/* 272 */       Log.c(a, 
/* 273 */         i + 
/* 274 */         ":\tClientProtocolException,Failed to send message." + 
/* 275 */         paramString, localClientProtocolException);
/* 276 */       return null;
/*     */     } catch (Exception localException) {
/* 278 */       Log.c(a, i + ":\tIOException,Failed to send message." + paramString, 
/* 279 */         localException);
/* 280 */     }return null;
/*     */   }
/*     */ 
/*     */   private HttpParams a()
/*     */   {
/* 285 */     BasicHttpParams localBasicHttpParams = new BasicHttpParams();
/* 286 */     HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 10000);
/* 287 */     HttpConnectionParams.setSoTimeout(localBasicHttpParams, 20000);
/* 288 */     HttpProtocolParams.setUserAgent(localBasicHttpParams, System.getProperty("http.agent"));
/* 289 */     return localBasicHttpParams;
/*     */   }
/*     */ 
/*     */   public s setHeader(Map<String, String> paramMap)
/*     */   {
/* 300 */     this.b = paramMap;
/* 301 */     return this;
/*     */   }
/*     */ 
/*     */   private void b(String paramString) {
/* 305 */     String str = paramString;
/* 306 */     if ((h.d(str)) || 
/* 308 */       (!(t.c.equals(str.trim()) ^ t.b
/* 308 */       .equals(str.trim()))))
/* 309 */       throw new RuntimeException("验证请求方式失败[" + str + "]");
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.common.net.s
 * JD-Core Version:    0.6.2
 */